package com.cl.base.exception;

import com.cl.base.constant.ResultCode;
import com.cl.base.constant.StatusCode;
import lombok.Getter;

import java.io.Serial;

@Getter
public class ServiceException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;

    private final int code;
    private final String msg;

    // 手动设置异常
    public ServiceException(StatusCode statusCode) {
        super(statusCode.getMsg());
        // 状态码
        this.code = statusCode.getCode();
        // 状态码配套的msg
        this.msg = statusCode.getMsg();
    }

    // 默认异常使用 ResultCode.FAILED 状态码
    public ServiceException(String msg) {
        super(msg);
        this.code = ResultCode.FAILED.getCode();
        this.msg = msg;
    }
}
